



import axios from 'axios'

import qs from 'qs'

export const getAccessToken = async (data: {appKey:string, appSecret: string}): Promise<any> => {
    let res = await axios<any>({
        url: 'https://open.ys7.com/api/lapp/token/get',
        method: 'post',
        data: qs.stringify(data)
    })
    
    return res.data
}

export const ptzStart = async (data: {
    accessToken: string,
    deviceSerial: string,
    channelNo: number,
    /**操作命令：0-上，1-下，2-左，3-右，4-左上，5-左下，6-右上，7-右下，8-放大，9-缩小，10-近焦距，11-远焦距，16-自动控制 */
    direction: number,
    /**云台速度：0-慢，1-适中，2-快，海康设备参数不可为0 */
    speed: number
}): Promise<any> => {
    let res = await axios<any>({
        url: 'https://open.ys7.com/api/lapp/device/ptz/start',
        method: 'post',
        data: qs.stringify(data)
    })
    return res.data
}

export const ptzStop = async (data: {
    accessToken: string,
    deviceSerial: string,
    channelNo: number,
    /**操作命令：0-上，1-下，2-左，3-右，4-左上，5-左下，6-右上，7-右下，8-放大，9-缩小，10-近焦距，11-远焦距，16-自动控制 */
    direction: number,
}): Promise<any> => {
    let res = await axios<any>({
        url: 'https://open.ys7.com/api/lapp/device/ptz/stop',
        method: 'post',
        data: qs.stringify(data)
    })
    return res.data
}

/**查询云录制的录像 */
export const videoByTime = async (data: {
    accessToken: string,
    deviceSerial: string,
    channelNo: number,
    startTime?: number,
    endTime?: number,
    recType?: number,
    version?: string,
    pageSize?: number
}) : Promise<any> => {
    data.recType = 1
    data.version = '2.0'
    data.pageSize = 100
    let res = await axios<any>({
        url: 'https://open.ys7.com/api/lapp/video/by/time',
        method: 'post',
        data: qs.stringify(data)
    })
    return res.data
}
/**查询本地录像 */
export const localVideoQuery = async (params:{
    accessToken: string,
    deviceSerial: string,
    localIndex: string,
    startTime: string,
    endTime: string,
    pageSize: number
}): Promise<any> => {
    let res = await axios<any>({
        url: 'https://open.ys7.com/api/v3/device/local/video/unify/query',
        method: 'get',
        headers: {
            accessToken: params.accessToken,
            deviceSerial: params.deviceSerial,
            localIndex: params.localIndex
        },
        params
    })
    return res.data
}
/**获取云录像的地址 */
export const replayAddress = async (params:{
    accessToken: string,
    deviceSerial: string,
    localIndex: string,
    startTime: string,
    stopTime: string
    spaceId: number
}): Promise<any> => {
    let res = await axios<any>({
        url: 'https://open.ys7.com/api/service/media/cloud/replay/address',
        method: 'get',
        headers: {
            accessToken: params.accessToken,
            deviceSerial: params.deviceSerial,
            localIndex: params.localIndex
        },
        params
    })
    return res.data
}
/**获取本地录像的播放地址 */
export const getLocalAddress = async (data:{
    accessToken: string,
    deviceSerial: string,
    channelNo: number,
    startTime: string,
    stopTime: string,
    type: number
}): Promise<any> => {
    
    let res = await axios<any>({
        url: 'https://open.ys7.com/api/lapp/v2/live/address/get',
        method: 'post',
        data:qs.stringify(data)
    })
    return res.data
}
/**获取指定设备的通道信息 */
export const deviceCameraList = async (data:{
    accessToken: string,
    deviceSerial: string,
}): Promise<any> => {
    
    let res = await axios<any>({
        url: 'https://open.ys7.com/api/lapp/device/camera/list',
        method: 'post',
        data:qs.stringify(data)
    })
    return res.data
}
/**获取NVR通道状态信息 */
export const nvrChannelStatus = async (data:{
    accessToken: string,
    deviceSerial: string,
}): Promise<any> => {
    
    let res = await axios<any>({
        url: 'https://open.ys7.com/api/v3/open/device/metadata/channel/status',
        method: 'get',
        headers: data
    })
    return res.data
}
